package com.ruoyi.eam.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eam.doman.EamSupplier;
import com.ruoyi.eam.service.IEamSupplierService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产供应商Controller
 * 
 * @author xl
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/supplier")
public class EamSupplierController extends BaseController
{
    @Autowired
    private IEamSupplierService eamSupplierService;

    /**
     * 查询资产供应商列表
     */
    //@RequiresPermissions("eam:supplier:list")
    @GetMapping("/list")
    public TableDataInfo list(EamSupplier eamSupplier)
    {
        startPage();
        List<EamSupplier> list = eamSupplierService.selectEamSupplierList(eamSupplier);
        return getDataTable(list);
    }

    /**
     * 导出资产供应商列表
     */
    //@RequiresPermissions("eam:supplier:export")
    @Log(title = "资产供应商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamSupplier eamSupplier)
    {
        List<EamSupplier> list = eamSupplierService.selectEamSupplierList(eamSupplier);
        ExcelUtil<EamSupplier> util = new ExcelUtil<EamSupplier>(EamSupplier.class);
        util.exportExcel(response, list, "资产供应商数据");
    }

    /**
     * 获取资产供应商详细信息
     */
    //@RequiresPermissions("eam:supplier:query")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Integer supplierId)
    {
        return success(eamSupplierService.selectEamSupplierBySupplierId(supplierId));
    }

    /**
     * 新增资产供应商
     */
    //@RequiresPermissions("eam:supplier:add")
    @Log(title = "资产供应商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamSupplier eamSupplier)
    {
        return toAjax(eamSupplierService.insertEamSupplier(eamSupplier));
    }

    /**
     * 修改资产供应商
     */
    //@RequiresPermissions("eam:supplier:edit")
    @Log(title = "资产供应商", businessType = BusinessType.UPDATE)
    @PutMapping("/updateSupplier")
    public AjaxResult edit(@RequestBody EamSupplier eamSupplier)
    {
        return toAjax(eamSupplierService.updateEamSupplier(eamSupplier));
    }

    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody List<EamSupplier> eamSuppliers)
    {
        return toAjax(eamSupplierService.updateStatus(eamSuppliers));
    }

    /**
     * 删除资产供应商
     */
    //@RequiresPermissions("eam:supplier:remove")
    @Log(title = "资产供应商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Integer[] supplierIds)
    {
        return toAjax(eamSupplierService.deleteEamSupplierBySupplierIds(supplierIds));
    }
}
